package scheduler;

import org.junit.Before;
import org.junit.Test;
import us.codecraft.webmagic.Request;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.scheduler.RedisPriorityScheduler;
import util.ReadFile;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;

public class UploadJob {
    private RedisPriorityScheduler scheduler;
    private static final String searchURL = "https://www.qichacha.com/search?key=";

    @Before
    public void setUp()
    {
        scheduler = new RedisPriorityScheduler("172.16.234.143");
    }

    @Test
    public void upload(){
        Task task = new Task() {
            @Override
            public String getUUID() {
                return "www.qichacha.com";
            }

            @Override
            public Site getSite() {
                return null;
            }
        };
        scheduler.resetDuplicateCheck(task);

        ArrayList<String> list = ReadFile.readFile("D:/GitlabWorkspace/QichachaCrawler/crawler/src/company_list");

        String job_id = "TESTING_北京投资公司汇总上报版_20181113";
        for(String word:list){
            Request request = new Request();
            request.setUrl(searchURL+word);
            Map<String,Object> extras = new HashMap<String, Object>();
            extras.put("search_word",word);
            extras.put("search_word_matched_type","");
            extras.put("job_id",job_id);
            extras.put("InitialPriority","0");
            extras.put("MinInvestmentPriority","0");
            extras.put("MinShareholderPriority","0");
            extras.put("MinChangePriority","0");
            extras.put("MinPledgePriority","0");
            request.setExtras(extras);
            request.setPriority(0).putExtra("name",job_id);
            scheduler.push(request,task);
        }
    }
}
